import { createApp, type Component } from 'vue';
/**
 * 函数式调用组件的一种方法，详见钉钉文档⌈活动项目hooks指南⌋
 * @params comp 需要渲染的组件
 * @params config 传递给组件的props、attrs、emits等
 */
export function useRender(comp: Component, config = {}) {
    const realDOM = document?.createElement('div');
    if (realDOM) {
        const app = createApp(comp, {
            ...config,
            onClosed: () => {
                if (document?.body?.contains?.(realDOM)) {
                    document?.body?.removeChild?.(realDOM);
                }
            },
        });
        document?.body?.insertBefore?.(realDOM, document.body.firstChild);
        app.mount(realDOM);
    }
}
